#include <iostream>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <fstream>
using namespace std;
constexpr double pi = 3.1415926535897932;
struct Branin
{
    double operator()(const double x1, const double x2)
    {
        return pow(15 * x2 - 5.1 / (4 * pi * pi) * (15 * x1 - 5) * (15 * x1 - 5) + 5 / pi * (15 * x1 - 5) - 6, 2) + 10 * ((1 - 1.0 / (8 * pi)) * cos(15 * x1 - 5) + 1) + 5 * x1;
    }
};

int main()
{
    Branin bra;
    ofstream of22{"branin.dat"};
    of22 << scientific << setprecision(15);
    of22 << " variables = \"x1\", \"x2\", \"f\"\n";
    of22 << "ZONE T=\"exact\" I = 101, J = 101\n";
    int range = 100;
    double dx = 0.01, x1, x2;
    //1  VectorXd tmp2(2);
    for (int i = 0; i <= range; ++i)
        for (int j = 0; j <= range; ++j)
        {
            x1 = i * dx;
            x2 = dx * j;
            of22 << x1 << "  " << x2 << "  " << bra(x1, x2) << "\n";
        }
    of22.close();

    ofstream of{"constraint.dat"};
    of << scientific << setprecision(15);
    of << " variables = \"x1\", \"x2\"\n";
    of << "ZONE T=\"cos\" I = 91\n";
    //1  VectorXd tmp2(2);
    for (int i = 10; i <= range; ++i)
    {
        x1 = i * dx;
        of << x1 << "  " << 0.2 / x1 << "\n";
    }
    of.close();
    return 0;
}